package com.zw.yzk.kabu.data.repository;


import com.zw.yzk.kabu.data.network.entity.Entity;
import com.zw.yzk.kabu.data.network.task.Task;
import com.zw.yzk.kabu.data.constant.Constant;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.service.PublishCosService;
import com.zw.yzk.kabu.data.network.task.PublishCosTask;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2017/1/16.
 */

public class PublishCosRepository extends CommonRepository {

    @Inject
    public PublishCosRepository() {

    }

    @Override
    protected Observable connectServer(Task task) {
        final PublishCosService service = ServiceGenerator.createService(PublishCosService.class);
        PublishCosTask qiniuTask = (PublishCosTask) task;

        return service.publishCos(qiniuTask);
    }

    @Override
    protected Func1<Entity, Observable> getServerData() {
        return new Func1<Entity, Observable>() {
            @Override
            public Observable call(Entity entity) {
                return Observable.just(entity.errCode == Constant.RESULT_OK);
            }
        };
    }
}
